package com.example.spring.demo.common.result;

import com.example.spring.demo.common.error.ErrorCodeEnum;
import lombok.Data;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2024/12/25 21:46
 **/
@Data
public class Result<T> {
    private String code;
    private String msg;
    private T data;

    public Result(String code, String message, T data) {
        this.code = code;
        this.msg = message;
        this.data = data;
    }

    public static <T> Result<T> success(T data) {
        return new Result<>("200", "成功", data);
    }

    public static Result<?> error(String message) {
        return new Result<>("-1", message, null);
    }

    public static Result<?> error(String code, String message) {
        return new Result<>(code, message, null);
    }

    public static Result<?> error(ErrorCodeEnum errorCodeEnum) {
        return new Result<>(errorCodeEnum.getErrorCode(), errorCodeEnum.getErrorMessage(), null);
    }
}
